/**
 * 
 */
package com.jacen.fzxs.manager;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yanzihui 2012-9-17
 */
public class GetRequest extends HttpServletRequestWrapper {
	private static final String DEFAULT_CHARSET = "UTF-8";
	private static Logger logger = LoggerFactory.getLogger(GetRequest.class);

	/**
	 * @param request
	 */
	public GetRequest(HttpServletRequest request) {
		super(request);
	}

	@Override
	public String getParameter(String name) {
		String value = super.getParameter(name);
		try {
			if (value != null) {
				value = new String(value.getBytes("ISO8859-1"), DEFAULT_CHARSET);
			}
		} catch (UnsupportedEncodingException e) {
			logger.error(e.getMessage());
		}
		return value;
	}

	@Override
	public String[] getParameterValues(String name) {
		String[] values = super.getParameterValues(name);
		if (values == null || values.length == 0)
			return null;

		String[] temps = Arrays.copyOf(values, values.length);
		try {
			for (int i = 0; i < temps.length; i++) {
				String value = temps[i];
				temps[i] = new String(value.getBytes("ISO8859-1"), DEFAULT_CHARSET);
			}
		} catch (UnsupportedEncodingException e) {
			logger.error(e.getMessage());
		}
		return temps;
	}
}
